<template>
  <div class="top">
    <div class="content">
      <div class="left" @click="goHome">
        <img src="@/assets/logo.svg" alt="" />
        <p>
          尚医通 预约挂号统一平台
          <!-- vue3 -->
        </p>
      </div>
      <div class="right">
        <p class="help">帮助中心</p>
        <p class="login" @click="showLogin" v-if="!userStore.userInfo.name">登录/注册</p>
        <el-dropdown v-else @command="handleCommand">
          <span class="el-dropdown-link">
            {{ userStore.userInfo.name }}
            <el-icon class="el-icon--right">
              <ArrowDown />
            </el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item command="auth">实名认证</el-dropdown-item>
              <el-dropdown-item command="order">挂号订单</el-dropdown-item>
              <el-dropdown-item command="patient">就诊人管理</el-dropdown-item>
              <el-dropdown-item command="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ArrowDown } from '@element-plus/icons-vue'
import { useRouter } from 'vue-router'
const $router = useRouter()
// 获取store
import useUserStore from '@/store/modules/user'
const userStore = useUserStore()

// 点击注册登录的时候,弹框显示登录
const showLogin = () => {
  userStore.visiable = true
}
const goHome = () => {
  $router.push('/')
}

const handleCommand = (command: string) => {
  if(command == 'auth'){
    $router.push('/user/auth')
  }else if(command == 'order'){
    $router.push('/user/order')
  }else if(command == 'patient'){
    $router.push('/user/patient')
  }else{
    // 通知仓库清除信息
    console.log('退出', command)
    userStore.logout()
    $router.push('/')
  }
}
</script>
<style scoped lang="scss">
.top {
  height: 70px;
  width: 100%;
  background: #fff;
  position: fixed;
  box-shadow: 0px 3px 5px #efefef;
  z-index: 999;
  .content {
    height: 100%;
    width: 80%;
max-width: 1400px;
min-width: 1000px;
    background-color: #fff;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    .left {
      display: flex;
      align-items: center;
      cursor: pointer;
      img {
        width: 50px;
        height: 50px;
        margin-right: 10px;
      }
      p {
        color: #55a6fe;
        font-size: 20px;
      }
    }
    .right {
      display: flex;
      align-items: center;
      justify-content: center;
      color: #aaa;
      color: 14px;
      cursor: pointer;
      .help {
        margin-right: 20px;
      }
    }
  }
}
</style>
